var e = require("../../api.js"), rr = require("../../utils.js"), o = getApp();

Page({
    data: {
        order: null,
        getGoodsTotalPrice: function() {
            return this.data.order.total_price;
        }
    },
    onLoad: function(t) {
      console.log('dddsss');
      if (t.scene) {
        var m = decodeURIComponent(t.scene);
        var hh = rr.scene_decode(m);
        if (hh.user_id != '' && hh.user_id != undefined && hh.user_id != null && hh.user_id != 0) {
          t.user_id = hh.user_id
        }else{
          t.user_id = 0;
        }
      }


        o.pageOnLoad(this, t);
        var r = this, n = "";
        if ("undefined" == typeof my) n = t.scene; else if (null !== o.query) {
            var c = o.query;
            o.query = null, n = c.order_no;
        }
        r.setData({
            store: wx.getStorageSync("store"),
            user_info: wx.getStorageSync("user_info")
        }), wx.showLoading({
            title: "正在加载"
        }), o.request({
            url: e.order.clerk_detail,
            data: {
                order_no: n,
                user_id:t.user_id
            },
            success: function(e) {
                0 == e.code ? r.setData({
                    order: e.data
                }) : wx.showModal({
                    title: "警告！",
                    showCancel: !1,
                    content: e.msg,
                    confirmText: "确认",
                    success: function(e) {
                        e.confirm && wx.redirectTo({
                            url: "/pages/index/index"
                        });
                    }
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    clerk: function(t) {
        var r = this;
        wx.showModal({
            title: "提示",
            content: "是否确认核销？",
            success: function(t) {
                t.confirm ? (wx.showLoading({
                    title: "正在加载"
                }), o.request({
                    url: e.order.clerk,
                    data: {
                        order_no: r.data.order.order_no
                    },
                    success: function(e) {
                      0 == e.code ? wx.showModal({
                        title: "提示",
                        showCancel: !1,
                        content: e.msg,
                        confirmText: "确认",
                        success: function (e) {
                          e.confirm && wx.redirectTo({
                            url: "/pages/user/user"
                          });
                        }
                      }) : wx.showModal({
                                  title: "警告！",
                                  showCancel: !1,
                                  content: e.msg,
                                  confirmText: "确认",
                                  success: function(e) {
                                      e.confirm && wx.redirectTo({
                                          url: "/pages/index/index"
                                      });
                                  }
                              });
                    },
                    complete: function() {
                        wx.hideLoading();
                    }
                })) : t.cancel;
            }
        });
    },
  clerkUser: function (t) {
    var r = this;
    var order_list = {};
    for (var i=0;i<r.data.order.order_list.length;i++){
      if (r.data.order.order_list[i].hexiao==1){
        order_list[i] = r.data.order.order_list[i].order_id;
      }
    }
    console.log(order_list);

    wx.showModal({
      title: "提示",
      content: "是否确认核销？",
      success: function (t) {
        t.confirm ? (wx.showLoading({
          title: "正在加载"
        }), o.request({
          url: e.order.clerk,
          data: {
            order_id_arr: order_list
          },
          success: function (e) {
            0 == e.code ? wx.showModal({
              title: "提示",
              showCancel: !1,
              content: e.msg,
              confirmText: "确认",
              success: function (e) {
                e.confirm && wx.redirectTo({
                  url: "/pages/commander/index"
                });
              }
            }) : wx.showModal({
              title: "警告！",
              showCancel: !1,
              content: e.msg,
              confirmText: "确认",
              success: function (e) {
                e.confirm && wx.redirectTo({
                  url: "/pages/index/index"
                });
              }
            });
          },
          complete: function () {
            wx.hideLoading();
          }
        })) : t.cancel;
      }
    });
  },
  getHexiao: function (t) {
    var e = this, a = t.currentTarget.dataset.hexiao, i = t.currentTarget.dataset.index;
    e.data.order.order_list[i].hexiao = a;
    e.setData({
      order:e.data.order
    })
  },
});